﻿<html>
    <head>
        <title>Блог</title>
        <link rel='stylesheet' type='text/css' href='main.css'> 
        <script type="text/javascript" src="jquery-1.8.1.js"></script>
        <script>
            function addKarma(userID, curUserID) {
                $.ajax({  
                    type: "POST",  
                    url: "index.php?controller=Karma",  
                    data: "userID="+userID,  
                    success: function(html){  
                        $(".u"+userID).html(html);
                    }  
                });  
            }
        </script>
    </head>
    
    <body>
        <div class='hat'><a href='index.php'>Блог</a>
        </div>
        
        <div class='auth'>
        Здравствуй, <?=$this->user->fName.' '.$this->user->lName?>!<br><br>
        
        <? if ( $this->user->id == false ) {?>
            <form action='index.php?controller=auth' method='post'>
                <input type='text' size='10' name='userName'>
                <input type='password' size='10' name='password'>
                <input type='submit' value='login'>
                &nbsp <a href='index.php?controller=reg'>[Регистрация]</a>
            </form>
        <? } else {?>
        <a href='index.php?controller=write'>Новая статья</a>
        &nbsp | &nbsp
        <a href='index.php?controller=index&logout=1'>Выйти</a>
        <? if ( $this->user->userName == 'admin' ) {?>
        &nbsp | &nbsp
        <a href='index.php?controller=admin'>Авторы</a>
        <?}?>
        <br><br>
        <? } ?>
        </div>
        <div class='articles'>
            <? if ($this->articles) {?>
                <? foreach($this->articles as $article) {?>
                
                <div class='art'>
                    <div class='art_subj'><?=$article->subject?></div>
                    
                    <?if ($article->tags[0]) {?>
                    <div class='art_tags'>[
                    <? for ($it=0; $it<sizeof($article->tags); $it++) {?> 
                    <a href='index.php?tag=<?=$article->tags[$it]?>'><?=$article->tags[$it]?></a>
                    <?if (isset($article->tags[$it+1])){?>,<?}?>
                    <?}?>
                    ]</div>
                    <?}?>
                    
                    <div class='art_text'><?=$article->text?></div>
                    <div class='karmaBlock'>
                        <div class='plus_karma'><a onclick='addKarma(<?=$article->userID?>)'>+</a></div>
                        <div class='karma'><div class='u<?=$article->userID?>'><?=$article->karma?></div></div>
                    </div>
                    <div class='art_info'>
                    <?=$article->time?> <b>by</b> 
                    <a href='index.php?authorID=<?=$article->userID?>'><?=$article->userFullName?></a>
                    </div>
                    
                    <div class='art_comments'>
                    <a href='index.php?controller=comment&artID=<?=$article->id?>'>Комментировать</a>
                     | <a href='index.php?controller=comment&artID=<?=$article->id?>'>
                    <?=$article->comCount?> комментариев </a>
                    </div>
                    
                    <? if ( $article->userID == $this->user->id ) {?>
                    <div class='art_ed'><a href='index.php?controller=edit&id=<?=$article->id?>'>Редактировать</a> | 
                    <a href='index.php?controller=index&del=1&id=<?=$article->id?>'>Удалить</a></div>
                    <? } ?>
                
                </div>
                
                <? } ?>
            <? } ?>
        </div>
    </body>
</html>